function on_publish(topic, pyload, qos, client_id) {
  wx.request({
    url: 'http://15b3t97519.51mypc.cn/api/v3/mqtt/publish',
    data: {
      "topic": topic,
      "payload": pyload,
      "qos": 1,
      "retain": false,
      "client_id": client_id
    },
    header: {
      "Content-Type": "application/json",
      "Authorization": "Basic YWRtaW46cHVibGlj"
    },
    method: "POST",
    success: function (res) {
      // console.log(res.data);
      return res.data;
    }
  })
}

function strToHexCharCode(str) {
  　　if (str === "")
    　　　　return "";
  　　var hexCharCode = [];
      for (var i = 0; i < str.length; i++) {
        if(i%2==0){
          var h = str.charCodeAt(i);
          var l = str.charCodeAt(i+1);
          if (h>=97){
            h = 10+h-97;
          }
          else{
            h = h-30;
          }
          if (l >= 97) {
            l = 10 + l - 97;
          }
          else{
            l = l - 30;
          }
          console.log(h*16+l);
          console.log(str.charCodeAt(i+1));
          var num = parseInt(str.charCodeAt(i) + str.charCodeAt(i + 1), 16);
          hexCharCode.push((h * 16 + l).toString(16));
        }
      }
  　　return hexCharCode.join("");
}

module.exports.on_publish = on_publish
exports.strToHexCharCode = strToHexCharCode